<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/commons/taglibs.jsp"%>
<script>
	$(document).ready(function() {
		//聚焦第一个输入框
		$("#name").focus();
		//为inputForm注册validate函数
		$("#inputForm").validate({
			rules : {
				department : "required",
				title : "required",
				context : "required",
				memo : "required",
				userName : "required",
				type : "required"
			}
		});
	});
</script>
<form id="inputForm" class="well form-inline" action="${ctx}/adoms/msgNotice/save" method="post">
	<input type="hidden" name="id" value="${msgNotice.id}" />
	<table class="table table-striped table-bordered table-condensed">
		<thead>
			<i class="icon-flag"></i>
			<strong>消息表单</strong>
		</thead>
		<tr>
			<td class="span2">标题:</td>
			<td>
				<input id="title" class="tWidth90" name="title" type="text" value="${msgNotice.title}" size="30" maxlength="80" />
			</td>
		</tr>
		<tr>
			<td>消息类型:</td>
			<td>
				<select id="type" name="type.id">
					<c:forEach items="${typeList }" var="type">
						<option value="${type.id }" <c:if test="${msgNotice.type.id == type.id}">selected</c:if>>${type.name }</option>
					</c:forEach>
				</select>
			</td>
		</tr>
		<tr>
			<td>范围:</td>
			<td>
				<label class="radio">
					<input value="全部" name="narea" type="radio" checked="checked" />
					全部
				</label>
				<label class="radio">
					<input value="本部门" name="narea" type="radio" />
					本部门
				</label>
				<label class="radio">
					<input value="下级部门" name="narea" type="radio" />
					下级部门
				</label>
			</td>
		</tr>
		<tr id="departmentTr" class="hide">
			<td>下级部门:</td>
			<td>
				<select disabled="disabled" id="toDepartment" name="toDepartment.id">
					<c:forEach items="${toDepartments }" var="d">
						<option value="${d.id }" <c:if test="${msgNotice.toDepartment.id == d.id}">selected</c:if>>${d.name }</option>
					</c:forEach>
				</select>
			</td>
		</tr>
		<tr>
			<td valign="top">主要内容:</td>
			<td>
				<textarea id="context" class="tWidth98 hide" name="context" rows="2">${msgNotice.context}</textarea>
				<iframe name="context" style="visibility: hidden; height: 0px;" src="${ctx }/resources/ckeditor/ckeditor.html"> </iframe>
			</td>
		</tr>
		<tr>
			<td class="span2">所属部门:</td>
			<td>
				<select id="department" name="department.id">
					<option value="${USER.department.id }">${USER.department.name }</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>消息发送人:</td>
			<td>
				<input id="userName" name="userName" type="text" value="${msgNotice.userName == null ? USER.name:msgNotice.userName}" size="30" maxlength="80" />
			</td>
		</tr>
		<tr>
			<td valign="top">备注:</td>
			<td>
				<textarea id="memo" name="memo" rows="4" class="span6">${msgNotice.memo}</textarea>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
				<input class="btn span1 btn-primary" type="submit" value="提交" />
				&nbsp;
				<input class="btn span1" type="button" value="返回" back="back" />
			</td>
		</tr>
	</table>
</form>
<script>
	$(function() {
		$("iframe").load(function() {
			$("textarea", $(this).contents()).val($("#context").val());
		});
		$("input[name=narea]").click(function() {
			if ($(this).val() == "下级部门") {
				$("#toDepartment").removeAttr("disabled");
				$("#departmentTr").show();
			} else {
				$("#departmentTr").hide();
				$("#toDepartment").attr("disabled", "disabled");
			}
		});
	});
</script>